/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __RESOURCEFACTORY_H__
#define __RESOURCEFACTORY_H__

#pragma once

#include <string>
#include <map>
#include <vector>

// Includes for the different factories
#include "common/Singleton.h"
#include "IResource.h"

#include "IModel.h"
#include "ITexture.h"
#include "ICubeMap.h"
#include "IShaderEffect.h"
#include "IFont.h"
#include "model/IModelBase.h"

#include "Thread.h"

/**
 * \ingroup CoreEngine
 *
 * The ResourceFactory class.<br>
 * A class for a factory model that loads resources
 *
 * \date 03-28-2007
 *
 * \author juckel
 *
 */
class DLL_EXPORT ResourceFactory 
//	: public Singleton<ResourceFactory>
{
public:
	ResourceFactory(void);
	virtual ~ResourceFactory(void);

	/// Delete the ResourceFactory and all its objects
	virtual void Destroy();

	/// Frees and removes a resource by reference from the loaded list
	virtual bool freeRes(IResource* resource);

	/// Frees all allocated resources
	virtual void freeAll();

	/// Reset all loaded resources
	virtual void resetAll();

	virtual void resetAllShaderEffects();

	/// Release all loaded resources
	virtual void releaseAll();

	/// Loads an 2D texture resource and returns the pointer
	virtual ITexture* loadTexture(const std::string &filename,bool dynamic = false, eFormat format = DEFAULT);

	/// Loads a cube map texture resource and returns the pointer
	virtual ICubeMap* loadCubeMap(const std::string &filename, bool dynamic = false, eFormat format = DEFAULT);

	/// Loads a normal map texture resource and returns the pointer
	virtual ITexture* createNormalMap(const std::string &filename);

	/// Loads an IModel resource and returns the pointer
	virtual IModel* loadModel(const std::string &filename);

	/// Loads a custom model resource and returns the pointer
	virtual model::IModelBase* loadCustomModel(const std::string &filename);
	
	/// Loads a new shader and returns the pointer
	virtual IShaderEffect* loadShaderEffect(const std::string &filename);

	/// Loads an bitmap font and returns the pointer
	virtual IFont* loadBitmapFont(const std::string &filename, const std::string &metrics, int size = 0);

	/// Loads a true type font and returns the pointer. The TrueType font must be found in the system
	virtual IFont* loadTrueTypeFont(const std::string &filename, int size, int style = FONT_NORMAL);

protected:
	typedef std::map<std::string, IResource*> res_map;	///< A map for storing all the IResource resources
	res_map m_mResources;	

	/// Type of the current renderer. This is obtained during initialization and used for creating the correct objects
	int iRendererType;

	thread::Mutex m_Mutex;
};

/**
 *  Returns a reference to the texture factory
 */
DLL_EXPORT
ResourceFactory* coreGetResourceFactory();


#endif